package com.spic.business.riskbase.hierarchy.controller;

import java.io.IOException;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.spic.common.log.annotation.Log;
import com.spic.common.log.enums.BusinessType;
import com.spic.business.riskbase.hierarchy.domain.RiskWorkStep;
import com.spic.business.riskbase.hierarchy.service.IRiskWorkStepService;
import com.spic.common.core.web.controller.BaseController;
import com.spic.common.core.web.domain.AjaxResult;
import com.spic.common.core.utils.poi.ExcelUtil;
import com.spic.common.core.web.page.TableDataInfo;

/**
 * work_stepController
 *
 * @author ruoyi
 * @date 2023-04-14
 */
@RestController
@RequestMapping("/risk/work_step")
public class RiskWorkStepController extends BaseController
{
    @Autowired
    private IRiskWorkStepService riskWorkStepService;

    /**
     * 查询work_step列表
     */
    @GetMapping("/list")
    public TableDataInfo list(RiskWorkStep riskWorkStep)
    {
        startPage();
        List<RiskWorkStep> list = riskWorkStepService.selectRiskWorkStepList(riskWorkStep);
        return getDataTable(list);
    }

    /**
     * 导出work_step列表
     */
    @Log(title = "work_step", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, RiskWorkStep riskWorkStep) throws IOException {
        List<RiskWorkStep> list = riskWorkStepService.selectRiskWorkStepList(riskWorkStep);
        ExcelUtil<RiskWorkStep> util = new ExcelUtil<RiskWorkStep>(RiskWorkStep.class);
        util.exportExcel(response, list, "work_step数据");
    }

    /**
     * 获取work_step详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(riskWorkStepService.selectRiskWorkStepById(id));
    }

    /**
     * 新增work_step
     */
    @Log(title = "work_step", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody RiskWorkStep riskWorkStep)
    {
        return toAjax(riskWorkStepService.insertRiskWorkStep(riskWorkStep));
    }

    /**
     * 修改work_step
     */
    @Log(title = "work_step", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody RiskWorkStep riskWorkStep)
    {
        return toAjax(riskWorkStepService.updateRiskWorkStep(riskWorkStep));
    }

    /**
     * 删除work_step
     */
    @Log(title = "work_step", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(riskWorkStepService.deleteRiskWorkStepByIds(ids));
    }
}
